using System;
using System.Text;
using System.ComponentModel;
using System.Collections.Generic;
using System.Runtime.Serialization;
using System.Drawing;

namespace teavch.Utilities.Electrical.Design.Gui.LineDiagram
{

	public abstract class ElectricalSymbol : System.Windows.Forms.UserControl, ISerializable
	{

		private bool _fillGradiant = false;
		private SymbolState _state = SymbolState.Off;
		private SymbolStyle _style = SymbolStyle.Default;
		private System.Drawing.Pen _pen = System.Drawing.Pens.Lime;
		private System.Drawing.Brush _brush = System.Drawing.Brushes.Lime;

		private int _voltageLevel = 0;
		private int _symbolSize = 30;
		private int _borderWidth = 1;

		[Category( "Graphical Symbols for Single Line Diagrams" ), Description( "Get the value of drawing brush for Single Line Diagrams Symbol" ), DefaultValueAttribute( true )]
		public virtual System.Drawing.Brush Brush
		{
			get { return this._brush; }
			set
			{
				this._brush = value;
				this.Refresh();
			}
		}

		[Category( "Graphical Symbols for Single Line Diagrams" ), Description( "Get the value of drawing pen for Single Line Diagrams Symbol" ), DefaultValueAttribute( true )]
		public virtual System.Drawing.Pen Pen
		{
			get { return this._pen; }
			set
			{
				this._pen = value;
				this.Refresh();
			}
		}

		[Category( "Graphical Symbols for Single Line Diagrams" ), Description( "Get or set the value of Gradiant Fill in for Single Line Diagrams Symbol" ), DefaultValueAttribute( true )]
		public virtual bool Fill
		{
			get { return this._fillGradiant; }
			set
			{
				this._fillGradiant = value;
				this.Refresh();
			}
		}

		[Category( "Graphical Symbols for Single Line Diagrams" ), Description( "Get or set the style of the symbol" ), DefaultValueAttribute( true )]
		public virtual SymbolStyle Style
		{
			get { return this._style; }
			set
			{
				this._style = value;
				this.Refresh();
			}
		}

		[Category( "Graphical Symbols for Single Line Diagrams" ), Description( "Get or set the voltage level for Single Line Diagrams Symbol" ), DefaultValueAttribute( 11 )]
		public virtual int VoltageLevel
		{
			get { return this._voltageLevel; }
			set
			{
				this._voltageLevel = value;
				this.Refresh();
			}
		}

		[Category( "Graphical Symbols for Single Line Diagrams" ), Description( "Get or set the State for Single Line Diagrams Symbol" ), DefaultValueAttribute( SymbolState.Off )]
		public virtual SymbolState State
		{
			get { return this._state; }
			set
			{
				this._state = value;
				this._brush = this._state == SymbolState.On ? System.Drawing.Brushes.Red : System.Drawing.Brushes.Lime;
				this._pen = this._state == SymbolState.On ? System.Drawing.Pens.Red : System.Drawing.Pens.Lime;
				this.Refresh();
			}
		}

		[Category( "Graphical Symbols for Single Line Diagrams" ), Description( "Get or set the size for Single Line Diagrams Symbol" ), DefaultValueAttribute( 30 )]
		public virtual int SymbolSize
		{
			get { return this._symbolSize; }
			set
			{
				this._symbolSize = value;
				this.Refresh();
			}
		}

		[Category( "Graphical Symbols for Single Line Diagrams" ), Description( "Get or set the border width for Single Line Diagrams Symbols" ), DefaultValueAttribute( 1 )]
		public virtual int BorderWidth
		{
			get { return this._borderWidth; }
			set
			{
				this._borderWidth = value;
				this.Refresh();
			}
		}

		void ISerializable.GetObjectData( SerializationInfo info, StreamingContext context )
		{
			throw new NotImplementedException();
		}

		public virtual Point RotatePoint( Point pointToRotate, Point centerPoint, double angleInDegrees )
		{
			double angleInRadians = angleInDegrees * ( Math.PI / 180 );
			double cosTheta = Math.Cos( angleInRadians );
			double sinTheta = Math.Sin( angleInRadians );
			return new Point
			{
				X =
						( int )
						( cosTheta * ( pointToRotate.X - centerPoint.X ) -
						sinTheta * ( pointToRotate.Y - centerPoint.Y ) + centerPoint.X ),
				Y =
						( int )
						( sinTheta * ( pointToRotate.X - centerPoint.X ) +
						cosTheta * ( pointToRotate.Y - centerPoint.Y ) + centerPoint.Y )
			};
		}

		public virtual Point Rotate( Point point, Point pivot, double angleDegree )
		{
			double angle = angleDegree * Math.PI / 180;
			double cos = Math.Cos( angle );
			double sin = Math.Sin( angle );
			int dx = point.X - pivot.X;
			int dy = point.Y - pivot.Y;
			double x = cos * dx - sin * dy + pivot.X;
			double y = sin * dx + cos * dy + pivot.X;

			Point rotated = new Point( ( int ) Math.Round( x ), ( int ) Math.Round( y ) );
			return rotated;
		}


		private void InitializeComponent()
		{
			this.SuspendLayout();
			// 
			// ElectricalSymbol
			// 
			this.BackColor = System.Drawing.Color.Transparent;
			this.SetStyle( System.Windows.Forms.ControlStyles.SupportsTransparentBackColor, true );
			this.Name = "ElectricalSymbol";
			this.ResumeLayout(false);

		}

	}

	#region Enums
	public enum SymbolStyle
	{
		Default = 0,
		Advance = 1
	}

	public enum SymbolDirection
	{
		Left = 0,
		Top = 1,
		Right = 2,
		Bottom = 3
	}

	public enum SymbolOrientation
	{
		Horizontal,
		Verticle
	}

	public enum ConnectHands
	{
		None = 0,
		LefOrToptHand = 1,
		RightOrBottomHand = 2,
		Both = 3
	}

	public enum SymbolState
	{
		Off,
		On,
		SwitchingOff,
		SwitchingOn,
		Offline
	}

	public enum TrasformerType
	{
		TwoWindingTrasformer = 1,
		ThreeWindingTrasformer = 2,
		AutoTrasformer = 3,
		CurrentTrasformer = 4,
		PotentialTrasformer = 5
	}

	#endregion Enums

}
